package com.zxd.controller;

import com.zxd.core.Constant;
import com.zxd.entity.Module;
import com.zxd.entity.Role;
import com.zxd.entity.vo.BaseVo;
import com.zxd.entity.vo.TreeVo;
import com.zxd.service.FileService;
import com.zxd.service.GroupService;
import com.zxd.service.ModuleService;
import com.zxd.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 公共方法控制层
 * Created by 涂奕恒 on 2016/10/18.
 */
@Controller
@RequestMapping(value = "common")
public class CommonsController {

    @Autowired
    private ModuleService moduleService;

    @Autowired
    private FileService fileService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private GroupService groupService;

    /**
     * 一级菜单列表
     */
    @RequestMapping("/menuList")
    @ResponseBody
    public List<Module> menuList(Integer parentId) {
        return moduleService.findListByParentId(null == parentId ? Constant.CHECK_STATUS_DEFAULT : parentId);
    }

    /**
     * 下级菜单列表
     */
    @RequestMapping("/powerList")
    @ResponseBody
    public List<Module> powerList(Integer roleId) {
        return moduleService.findListNoParentId(roleId);
    }

    /**
     * 组织结构列表
     */
    @RequestMapping("/groupList")
    @ResponseBody
    public List<TreeVo> groupList() {
        return groupService.groupList();
    }

    /**
     * 角色列表
     */
    @RequestMapping("/roleList")
    @ResponseBody
    public List<Role> roleList() {
        return roleService.findListNoMaster();
    }

    /**
     * 上传文档
     */
    @RequestMapping("/uploadFile")
    @ResponseBody
    public BaseVo uploadFile(HttpServletRequest request, MultipartRequest multipartRequest) {
        return fileService.uploadFile(request, multipartRequest);
    }
}
